#include "at32project_header.h"


#define SRAM_96K		0xFF
#define SRAM_224K		0xFE

#define EOPB0			(0x1FFFF810)
#define F_EOPB0		(*(uint32_t*)EOPB0)

void Extend_SRAM(void)
{
#ifndef BOOTLOADER
	// check if RAM has been set to 224K, if not, change EOPB0
	if((F_EOPB0 & 0xFF) != 0xFE)
	{
		/* Unlock Option Bytes Program Erase controller */
		flash_unlock();
		
		/* Erase Option Bytes */
		flash_user_system_data_erase();
		
		/* Change SRAM size to 224KB */
		flash_user_system_data_program(EOPB0,0xFE);
		
		/* Lock the flash */
		flash_lock();
		
		/* Must Reset the system */
		NVIC_SystemReset();
	}
#endif
	
}

#ifndef BOOTLOADER
void *$Sub$$malloc(size_t size)
{
//		SEGGER_RTT_printf(0, "malloc %d\r\n" , size);
		return pvPortMalloc(size);
}

void $Sub$$free(void* ptr)
{
	vPortFree(ptr);
}

#endif
